<!-- CSS styles -->
<link rel='stylesheet' type='text/css' href='${cssRoot}plugins/jquery.snippet.css' />
<script src="${contentRoot}${contentid}/${contentid}.js"></script>
<script src="${scriptRoot}plugins/snippet/jquery.snippet.min.js"></script>
<script src="${scriptRoot}tinybox/tinybox.js"></script>
<script type="text/javascript" src="${commonRoot}ckplayer/ckplayer.js" charset="utf-8"></script>
<link rel='stylesheet' type='text/css' href='${scriptRoot}tinybox/tinybox.css' />
<script> 
//初始化内容
function initContent(){
	var progress = "";
	
	var flashvars={
        f:'http://movie.ks.js.cn/flv/other/1_0.mp4',
        c:0,
        e:0,
        loaded:'loadedHandler',
        my_url:window.location.href
    };
    var video=['http://movie.ks.js.cn/flv/other/1_0.mp4->video/mp4'];
    
	if(content.total > 1){
		progress = " （" + content.point + "/" + content.total + "）";
	}
	$("#title").text(content.title + progress);
	$("#task").load("${contentRoot}${contentid}/${contentid}-" + content.point + ".html", function() {
	  	$("#task").find("img").each(function(){
	  		var src = "${contentRoot}${contentid}/" + $(this).attr("src");
	  		
	  		if($(this).attr("alt") == "小讲"){
	  			src = "${uploadRoot}avatar/default.png";
	  		}
	  		
			$(this).attr("src", src);
			
			$(this).click(function(){
				TINY.box.show( "<img src='"+src+"' />",0,0,0,1);//控制图片的缩放
			})
		});
		$('pre.html').snippet('html');//控制代码区的显示
		$(".ckplayer").each(function(){
			  var ckid = $(this).attr("id");
			  var width=$(this).width();
			  var height=$(this).height();
			  var playContent=$(this).text();
			  flashvars.f="${contentRoot}${contentid}/"+playContent;
			  CKobject.embed('${commonRoot}ckplayer/ckplayer.swf',ckid,'ckplayer_'+ckid,width,height,false,flashvars,video);
		});
	});
	if(content.point == 1){
		$("#oper-prev").hide();
	}else{
		$("#oper-prev").show();
	}
	
	$("#oper-next").text((content.nexttxt)[content.point-1]);	
	var islast = 0;
	if(content.total == content.point){
		islast = 1;
	}
	$("#oper-next").attr("onclick", "setProgress(" + content.point +"," + islast + ")");
}

function prev(){
	if(content.point > 1){
		content.point = content.point - 1;
		initContent();
	}
}

function next(){
	if(content.point < content.total){
		content.point = content.point + 1;
		initContent();
	}
}
			
//设置任务进度，下一步、完成等动作发生时调用					
function setProgress(point, islast){
	jQuery.ajax({
		type : 'POST',
		url : '${webRoot}task/progress/${task.taskid?c}.do',
		data  :  {
				   contentid:${contentid},
		           point:point,
		           islast:islast
		          },
		dataType:'json',
		success : function(data){
			switch(data.CODE){
				case "1":
					if(islast == 1){
						//任务完成了，去学习中心
						location.href="${webRoot}center.do";
					}else{
						//数据保存成功，需要加载下一步的数据
						if(point > 0){//point==0保存首次进行的行为记录不做next()
							next();
						}
					}
					break;
				default:
					alert("错误：保存信息失败！请重试！");
			}
		},
		error : function(e) {
			//console.log(e);
		}
	});
}

$(document).ready(function() {
	//document.domain="dajiangtai.com";
	content.point = ${point};
	initContent();
	
	setProgress(0, 0);//记录用户进入任务的时间	
});
</script>